import { Dictionary } from "@/api/interface/auth/basic";
import { EnumProps } from "@/components/ProTable/interface";
import { publicType } from "@/interface/public";

interface statusProp {
  label: string;
  value: number | string;
  tagType?: publicType["colorType"];
}

/**
 * @param {String} names 需要获取数据字典的名称 (多个以逗号隔开)
 * @description 获取数据字典内容 children 中
 */
export const getDictionaryListByCodes = async (code: string) => {
  const str = code.split(",");

  const data: Dictionary.ResSearch[] = await dictionaryListByCodes({ code });
  if (!data) return [];
  if (str.length === 1) {
    return changeArrField(data[0]?.value, "dvalue") as EnumProps[];
  }

  let newObj: any = {};
  for (let item of data) {
    newObj[item.key] = changeArrField(item.value, "dvalue");
  }

  return newObj as { [key: string]: EnumProps[] };
};

/**
 * @description: 根据状态获取对应数据内容
 * @return {*}
 */
export const getStatusName = (arr: statusProp[], status: string | number) => {
  return arr.find(item => item.value + "" === status + "")?.label;
};

/**
 * @description：启用 0 |  禁用 1
 */
export const status1 = (): statusProp[] => {
  return [
    { label: "enable", value: 0, tagType: "success" },
    { label: "disabled", value: 1, tagType: "danger" }
  ];
};

/**
 * @description： 保存 0 | 提交 1
 */
export const status2 = (): statusProp[] => {
  return [
    { label: "save", value: 0, tagType: "warning" },
    { label: "submit", value: 1, tagType: "success" }
  ];
};

/**
 * @description：是  1| 否 0
 */
export const status3 = (): statusProp[] => {
  return [
    { label: "否", value: 0 },
    { label: "是", value: 1 }
  ];
};

/**
 * @description：系统标识
 */
export const systemCodeOp = (): statusProp[] => {
  return [{ label: "mes", value: "MES" }];
};
